<?php
class system_image_factory {
	
	public static $defaultImplemenation = 'gd';
	
	/**
	 * @return system_image_thumbGd
	 */
	public static function create($filename = null, $options = array(), $isDataStream = false) {		
		$implementationMap = array('imagick' => 'system_image_thumbImagick', 'gd' => 'system_image_thumbGd');		
		$pt = system_image_thumb::getInstance();
		$toReturn = null;
		$implementation = self::$defaultImplemenation;		
		if($pt->isValidImplementation(self::$defaultImplemenation)) {
			$imp = $implementationMap[self::$defaultImplemenation];
			$toReturn = new $imp($filename, $options, $isDataStream);
		} elseif($pt->isValidImplementation('gd')) {
			$imp = $implementationMap['gd'];
			$implementation = 'gd';
			$toReturn = new $imp($filename, $options, $isDataStream);
		} else {
			throw new system_exception('You must have either the GD or iMagick extension loaded to use this library');
		}	
		$registry = $pt->getPluginRegistry($implementation);
		return $toReturn;
	}

}
